package com.guigu.qingcheng.controller;

import com.guigu.common_util.pojo.utils.JwtUtils;
import com.guigu.qingcheng.entity.OrderItemLog;
import com.guigu.qingcheng.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class OrderIndexController {

    @Autowired
    private CartService orderServiceFeign;

    @GetMapping("centerIndex")
    private String centerIndex(){
        return "center-index";
    }

    /**
     * 我的订单
     * @return
     */
    @GetMapping("OrderItemLogList")
    @ResponseBody
    public List<OrderItemLog> OrderItemLogList(HttpServletRequest request){
        String username = JwtUtils.getMemberIdByJwtToken2(request);
        return this.orderServiceFeign.orderItemLogList(username);
    }

    /**
     * 订单详情
     * @return
     */
    @GetMapping("centerOrderDetail")
    public String centerOrderDetail(){
        return "centerOrderDetail";
    }

    /**
     * 待付款
     * @return
     */
    @GetMapping("centerOrderPay")
    public String centerOrderPay(){
        return "center-order-pay";
    }

    /**
     * 查询未付款
     * @return
     */
    @GetMapping("orderPayList")
    @ResponseBody
    public List<OrderItemLog> orderPayList(HttpServletRequest request){
        String username = JwtUtils.getMemberIdByJwtToken2(request);
        return this.orderServiceFeign.orderPayList(username);
    }

    /**
     * 待收货页面
     * @return
     */
    @GetMapping("centerOrderReceive")
    public String centerOrderReceive(){
        return "center-order-receive";
    }

    /**
     * 未收货
     * @return
     */
    @GetMapping("orderReceiveList")
    @ResponseBody
    public List<OrderItemLog> orderReceiveList(HttpServletRequest request){
        String username = JwtUtils.getMemberIdByJwtToken2(request);
        return this.orderServiceFeign.orderReceiveList(username);
    }

    /**
     * 跳转到待发货页面
     * @return
     */
    @GetMapping("centerOrderSend")
    public String centerOrderSend (){
        return "center-order-send";
    }

    /**
     * 未发货
     * @return
     */
    @GetMapping("centerOrderSendList")
    @ResponseBody
    public List<OrderItemLog> centerOrderSendList(HttpServletRequest request){
        String username = JwtUtils.getMemberIdByJwtToken2(request);
        return this.orderServiceFeign.centerOrderSend(username);
    }

    /**
     * 确认收货
     * @param orderId
     * @return
     */
    @GetMapping("updateconsignStatus")
    public String updateconsignStatus(@RequestParam("orderId") String orderId){
        this.orderServiceFeign.updateconsignStatus(orderId);
        return "center-index";
    }

}
